package com.SlideMenu.chatlove;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class SampleListFragment extends ListFragment {

	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.list, null);
	}

	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		SampleAdapter adapter = new SampleAdapter(getActivity());
		for (int i = 0; i < 20; i++) {
			adapter.add(new SampleItem("Perfect sdfksjdnfksdjdofjsodfijsdoifj", android.R.drawable.ic_menu_search,"9:10","Tuan"));
		}
		setListAdapter(adapter);
	}

	private class SampleItem {
		public String status;
		public int iconRes;
		public String time;
		public String name;
		public SampleItem(String status, int iconRes,String time,String name) {
			this.status = status; 
			this.iconRes = iconRes;
			this.time=time;
			this.name=name;
		}
		public String getStatus() {
			return status;
		}
		public void setStatus(String status) {
			this.status = status;
		}
		public int getIconRes() {
			return iconRes;
		}
		public void setIconRes(int iconRes) {
			this.iconRes = iconRes;
		}
		public String getTime() {
			return time;
		}
		public void setTime(String time) {
			this.time = time;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		
	}

	public class SampleAdapter extends ArrayAdapter<SampleItem> {

		public SampleAdapter(Context context) {
			super(context, 0);
		}

		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_info_index, null);
			}
			ImageView icon = (ImageView) convertView.findViewById(R.id.info_img_user);
			icon.setImageResource(getItem(position).iconRes);
			Button bt_name=(Button)convertView.findViewById(R.id.info_tb_name);
			TextView tv_time = (TextView) convertView.findViewById(R.id.info_tv_time_start_write);
			TextView tv_status = (TextView) convertView.findViewById(R.id.info_tv_status);
			
			bt_name.setText(getItem(position).name);
			tv_status.setText(getItem(position).status);
			tv_time.setText(getItem(position).time);

			return convertView;
		}

	}
}
